const http = require("http");
const fs = require("fs");

const server = http.createServer((request, response) => {
  // 获取请求url的路径
  let { pathname } = new URL(request.url, "http://127.0.0.1");
  if (pathname === "/") {
    let htmlData = fs.readFileSync(__dirname + "/table.html");
    response.end(htmlData);
  } else if (pathname === "/table.css") {
    let cssData = fs.readFileSync(__dirname + "/table.css");
    response.end(cssData);
  } else if (pathname === "/table.js") {
    let jsDtaa = fs.readFileSync(__dirname + "/table.js");
    response.end(jsDtaa);
  } else {
    response.end("Not Found");
  }
});

server.listen(9000, () => {
  console.log("服务已经启动...");
});
